import 'package:flutter/material.dart';

/*
 * 2019.12.23
 * DingHL
 * 行显示必填非必填计数
    行显示,必填非必填计数页面调用示例：
    Discover(
    isShowTwo: false,
    ),
 */

///todo：行显示（type属性控制不同的行类型：count 右边是必填非必填计数，input 右边是点击输入的输入框，switch 右边是点击选择）
class RowContainer extends StatefulWidget {
  //右边不同的类型（type属性控制不同的行类型：count 右边是必填非必填计数，input 右边是点击输入的输入框，switch 右边是点击选择）
  String type;
  ValueChanged<String> count;//非必填必填回调
  ValueChanged<String> input;//点击输入回调
  ValueChanged<String> choose;//点击选择回调
  VoidCallback onTap; //整行的点击事件
  double width; //整行的宽度
  Color iconRightColor; //右边图标颜色
  IconData iconRight; //右边图标
  double iconRightSize; //右边图标大小
  double leftTextSize; //左边字体大小
  String leftText; //左边字体
  Color leftTextColor; //左边字体颜色
  double height; //整行的高度
  String rightText1; //右边第一个字体
  String rightText2; //右边第二个字体
  String rightTextCount1; //右边第一个计数分子
  String rightTextCount2; //右边第一个计数分母
  String rightTextCount3; //右边第二个计数分子
  String rightTextCount4; //右边第二个计数分母
  Color rightTextColor1; //右边第一个字体颜色
  Color rightTextColor2; //右边第二个字体颜色
  double rightTextSize; //右边字体大小
  bool isShowTwo; //是否显示两个计数项（true显示两个计数项  false显示一个计数项）
  bool isShowStar; //是否显示星星图标（true显示星星图标  false不显示星星图标）
  Color inputColor; //输入字体的颜色
  Color hintTextColor; //提示字体颜色
  double fontSize; //输入框提示文本大小
  ValueChanged<String> onChanged; //内容改变事件
  TextEditingController textEditingController; //输入控制器
  bool isUpdate; //输入框文本是否可以修改
  TextInputType keyboardType; //弹出框键盘
  VoidCallback onEditingComplete; //文字提交触发（键盘按键）
  ValueChanged<String> onSubmitted; //文字提交触发（键盘按键）
  String hintText; //右侧文本框提示文字
  String switchText; //点击选择的值
  String switchDefaultText; //点击选择原始默认提示值
  int isComplete; //是否是已完成状态(0 不是已完成状态  1已完成状态)

  RowContainer(
      {Key key,
        this.type: "count",
        this.iconRightColor: Colors.black38,
        this.iconRight: Icons.chevron_right,
        this.iconRightSize: 25,
        this.leftTextSize: 16,
        this.onTap,
        this.width,
        this.leftText: "信息详情",
        this.leftTextColor: Colors.black,
        this.height: 56.0,
        this.rightText1: "非必填",
        this.rightText2: "必填",
        this.rightTextColor1: Colors.black54,
        this.rightTextColor2: Colors.red,
        this.rightTextSize: 14,
        this.rightTextCount1: "0",
        this.rightTextCount2: "10",
        this.rightTextCount3: "0",
        this.rightTextCount4: "10",
        this.isShowTwo: false,
        this.isShowStar: false,
        this.inputColor: Colors.black,
        this.fontSize: 15,
        this.onSubmitted,
        this.hintText: "点击输入",
        this.textEditingController,
        this.isUpdate: true,
        this.keyboardType,
        this.onChanged,
        this.onEditingComplete,
        this.hintTextColor,
        this.switchText,
        this.switchDefaultText: "点击选择",
        this.isComplete: 0,
        this.choose,
        this.input,
        this.count
      })
      : super(key: key);

  @override
  _RowContainerState createState() => _RowContainerState();
}

//焦点
final FocusNode _focusNode = new FocusNode();

class _RowContainerState extends State<RowContainer> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: widget.onTap,//整行的点击事件
      child: Container(
        width: widget.width ?? MediaQuery.of(context).size.width,
//        height: widget.height,
        color: Colors.white,
        padding: EdgeInsets.only(left: 15, right: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            //左边
            Container(
              height: widget.height,
              child: Row(
                children: <Widget>[
                  widget.isShowStar == true
                      ? Container(
                    padding: EdgeInsets.only(right: 5, top: 5),
                    alignment: Alignment.center,
                    child: Text(
                      '*',
                      style: TextStyle(
                          color: Colors.redAccent, fontSize: 25),
                      textAlign: TextAlign.center,
                    ),
                  )
                      : Container(),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      widget.leftText,
                      style: TextStyle(
                          color: widget.leftTextColor,
                          fontSize: widget.leftTextSize),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ],
              ),
            ),
            widget.type == "count"
                ?
            //右边(必填非必填)
            Container(
              child: Row(
                children: <Widget>[
                  widget.isShowTwo == true
                      ? Container(
                    padding: EdgeInsets.only(right: 10),
                    alignment: Alignment.center,
                    child: Text(
                      widget.rightText1 +
                          widget.rightTextCount1 +
                          "/" +
                          widget.rightTextCount2,
                      style: TextStyle(
                          color: widget.rightTextColor1,
                          fontSize: widget.rightTextSize),
                      textAlign: TextAlign.center,
                    ),
                  )
                      : Container(),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      widget.isComplete == 0
                          ? widget.rightText2 +
                          widget.rightTextCount3 +
                          "/" +
                          widget.rightTextCount4
                          : "已完成",
                      style: TextStyle(
                          color: widget.rightTextColor2,
                          fontSize: widget.rightTextSize),
                      textAlign: TextAlign.center,
                    ),
                  ),
                  //小图标
                  Container(
                    padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    child: Icon(
                      widget.iconRight ?? Icons.chevron_right,
                      color: widget.iconRightColor ?? Colors.black12,
                      size: widget.iconRightSize,
                    ),
                  ),
                ],
              ),
            )
                : widget.type == "switch"
                ?
            //右边(点击选择)
            Container(
                child: Wrap(
                  spacing: 5.0,
                  runSpacing: 0.0,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        InkWell(
                          child: Container(
                            width: MediaQuery.of(context).size.width /2,
                            alignment: Alignment.centerRight,
                            child: Text(
                              widget.switchText == null ||
                                  widget.switchText == ""
                                  ? widget.switchDefaultText
                                  : widget.switchText,
                              style: TextStyle(
                                  color: widget.switchText == null ||
                                      widget.switchText == ""
                                      ? Colors.black54
                                      : Colors.black,
                                  fontSize: 15),
                              textAlign: TextAlign.right,
                            ),
                          ),
                          onTap: widget.isComplete == 0 ?
                              widget.onTap
                              : () {},
                        ),

                        //小图标
                        Container(
                          padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                          child: Icon(
                            widget.iconRight ?? Icons.chevron_right,
                            color:
                            widget.iconRightColor ?? Colors.black12,
                            size: widget.iconRightSize,
                          ),
                        ),
                      ],
                    ),
                  ],
                ))
                : widget.type == "input"
                ?
            //右边(输入框)
            Container(
              padding: EdgeInsets.only(right: 5),
              width: MediaQuery.of(context).size.width / 2,
              child: TextField(
                focusNode: _focusNode,//键盘监听
//                maxLines: null,//加上此条可换行输入
                style: TextStyle(
                    color: widget.inputColor,
                    fontSize: widget.fontSize), //输入的字体样式
//              textAlign: TextAlign.left,
                textAlign: TextAlign.end,
                onChanged: widget.onChanged,
                controller: widget.textEditingController,
                cursorColor: Colors.black,
                cursorWidth: 1,
                enabled: widget.isUpdate,
                keyboardType: widget.keyboardType,
                onSubmitted: widget.onSubmitted,
                onEditingComplete: widget.onEditingComplete,
                //输入的类型
                decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: widget.hintText,
                  hintStyle: TextStyle(
                    //提示的字体样式
                    color: widget.hintTextColor,
                    fontSize: widget.fontSize, //14.0
                  ),
                ),
              ),
            )
                : Container(),
          ],
        ),
      ),
    );
  }
}